package com.maple.utils.util

import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.provider.Settings
import android.telephony.TelephonyManager
import android.text.TextUtils
import com.blankj.utilcode.util.DeviceUtils

class DeviceUtils {

    companion object {

        @JvmStatic
        fun getDeviceId(): String{
            return DeviceUtils.getAndroidID()
        }

        @JvmStatic
        fun getDeviceName(): String{
            return DeviceUtils.getModel()
        }

        @SuppressLint("MissingPermission")
        @JvmStatic
        fun getIMEI(context: Context): String{
            var imei: String = ""
            val telephonyManager: TelephonyManager? = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager?
            if(telephonyManager != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    try {
                        imei = telephonyManager.imei?.toString()?:""
                    }catch (e: Exception) {
                        imei = ""
                    }
                    if (TextUtils.isEmpty(imei)) {
                        imei = Settings.Secure.getString(
                            context.contentResolver,
                            Settings.Secure.ANDROID_ID
                        )
                    }
                } else {
                    imei = telephonyManager.deviceId
                }
            }
            return imei
        }

    }
}